package com.d0330;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class TestConstructor {
    public static void main(String[] args) {
        //通过字节码获得构造函数实例化对象
        try {
            //无参构造函数
            //Constructor<Account>con=Account.class.getConstructor();
            //Account account=con.newInstance();
            //有参构造函数
            Constructor<Account>con1=Account.class.getConstructor(int.class,int.class,double.class);
            Account account=con1.newInstance(188,123456,8000);
            System.out.println(account);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
